from typing import List
from utils import get_aver, matrix_mul, matrix_sub, get_pc, get_cm

def PCA(vects: List[List]) -> List[List]:
    '''
    使用主分析方法进行特征提取，将多维样本降至一维
    输入 样本集 形如 [ [1,1], [1,2], [1,3] ]
    输出 降至一维的样本集
    '''
    return [ matrix_mul(matrix_sub([v],[get_aver(vects)]),get_pc(get_cm(vects)))[0] for v in vects]




# for debug
# x1 = [[10,1]]
# x2 = [[9,0]]
# x3 = [[10,-1]]
# x4 = [[11,0]]
# x5 = [[0,9]]
# x6 = [[1,10]]
# x7 = [[0,11]]
# x8 = [[-1,10]]

# xs = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8
# res =  PCA(xs)
# print(res)